package com.platform.mvc.template.controller;



import org.apache.log4j.Logger;

import com.jfinal.aop.Before;

import com.platform.bean.DynamicConfig;
import com.platform.mvc.base.BaseController;
import com.platform.mvc.operator.OperatorController;
import com.platform.tools.util.TemplateConfigUtil;
/**
 * 后台类 - 动态模板
 * 
 */
public class TemplateDynamicController  extends BaseController{
	
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(TemplateDynamicController.class);
	private DynamicConfig dynamicConfig;
	private String templateFileContent;
	
	
	/**
	 *列表
	 * 
	 */ 
	public void index() {
			setAttr("dynamicConfigList", TemplateConfigUtil.getDynamicConfigList());
			render("/admin/template_dynamic_list.html");
		}
	/**
	 *编辑
	 * 
	 */  
		public void edit() {
			String dynamicConfigName = getPara("dynamicConfig.name","");
			dynamicConfig = TemplateConfigUtil.getDynamicConfig(dynamicConfigName);
			templateFileContent = TemplateConfigUtil.readTemplateFileContent(dynamicConfig);
			setAttr("dynamicConfig", dynamicConfig);
			setAttr("templateFileContent", templateFileContent);
			render("/admin/template_dynamic_input.html");
		}
		
		// 更新
		@Before(TemplateDynamicValidator.class)
		public void update() {
			String dynamicConfig_name = getPara("dynamicConfig.name","");
			templateFileContent = getPara("templateFileContent","");
			dynamicConfig = TemplateConfigUtil.getDynamicConfig(dynamicConfig_name);
			TemplateConfigUtil.writeTemplateFileContent(dynamicConfig, templateFileContent);
			redirect("/jf/platform/template");
		}
}
